\defmodule{UnuranDiscreteInt}

This class permits one to create a discrete univariate
generator using UNURAN via its string API.

\bigskip\hrule

\begin{code}
\begin{hide}
/*
 * Class:        UnuranDiscreteInt
 * Description:  create a discrete generator using UNURAN
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Universite de Montreal
 * Organization: DIRO, Universite de Montreal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   <a href="http://www.gnu.org/licenses">GPL licence site</a>.
 */
\end{hide}
package umontreal.iro.lecuyer.randvar;\begin{hide}
import umontreal.iro.lecuyer.probdist.DiscreteDistributionInt;
import umontreal.iro.lecuyer.rng.RandomStream;
\end{hide}

public class UnuranDiscreteInt extends RandomVariateGenInt\begin{hide} {

   private RandUnuran unuran = new RandUnuran();
\end{hide}\end{code}

\subsubsection* {Constructors}
\begin{code}

   public UnuranDiscreteInt (RandomStream s, String genStr)\begin{hide} {
      if (s == null)
         throw new IllegalArgumentException ("mainStream must not be null.");

      unuran.mainStream = unuran.auxStream = s;
      unuran.init (genStr);
      if (!unuran.isDiscrete()) {
         unuran.close();
         throw new IllegalArgumentException ("not a discrete distribution");
      }
   }\end{hide}
\end{code}
\begin{tabb}   
  Same as \method{UnuranDiscreteInt}{}~\texttt{(s, s, genStr)}.
\end{tabb}
\begin{code}

   public UnuranDiscreteInt (RandomStream s, RandomStream aux,
                             String genStr)\begin{hide} {
      if (s == null)
         throw new IllegalArgumentException ("mainStream must not be null.");
      if (aux == null)
         throw new IllegalArgumentException ("auxStream must not be null.");

      unuran.mainStream = s;
      unuran.auxStream = aux;
      unuran.init (genStr);
      if (!unuran.isDiscrete()) {
         unuran.close();
         throw new IllegalArgumentException ("not a discrete distribution");
      }
   }\end{hide}
\end{code}
\begin{tabb}
  Constructs a new discrete random number generator using
  the UNURAN generator specification string \texttt{genStr},
  main stream \texttt{s}, and auxiliary stream \texttt{aux}.
\end{tabb}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
\subsubsection* {Methods}

\begin{code}\begin{hide}

   public int nextInt() {
      if (unuran.nativeParams == 0)
         throw new IllegalStateException();
      return unuran.getRandDisc (unuran.mainStream.nextDouble(), unuran.nativeParams);
   }

   public void nextArrayOfInt (int[] v, int start, int n) {
      if (v == null || start < 0 || n < 0 || (start+n) > v.length)
         throw new IllegalArgumentException();
      if (unuran.unifArray == null || unuran.unifArray.length < n)
         unuran.unifArray = new double[n];
      if (unuran.mainStream != unuran.auxStream &&
         (unuran.unifAuxArray == null || unuran.unifAuxArray.length < n))
         unuran.unifAuxArray = new double[n];
      unuran.getRandDiscArray (unuran.nativeParams, unuran.unifArray,
                        unuran.unifAuxArray, v, start, n);
   }

   protected void finalize() {
      unuran.close();
   }

   public DiscreteDistributionInt getDistribution() { return null; }

   public RandomStream getStream() { return unuran.mainStream; }\end{hide}

   public RandomStream getAuxStream()\begin{hide} {
      return unuran.auxStream;
   }
}\end{hide}
\end{code}
\begin{tabb}   Returns the auxiliary random number stream.
\end{tabb}
